View Javadoc

1   /*
2    * Created on 13 déc. 2003
3    *
4    * To change the template for this generated file go to
5    * Window>Preferences>Java>Code Generation>Code and Comments
6    */
7   package net.sf.pmr.keopsframework.domain.object;
8   
9   import net.sf.pmr.keopsframework.data.GhostDomainObjectMapper;
10  import net.sf.pmr.keopsframework.domain.LoadStatusEnum;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  
15  
16  // TODO Trouver un moyen de tester cette classe.
17  
18  /***
19   * @author Arnaud To change the template for this generated type comment go to
20   *         Window>Preferences>Java>Code Generation>Code and Comments
21   */
22  
23  public abstract class AbstractGhostDomainObject extends AbstractDomainObject implements
24          GhostDomainObject {
25      /***
26       * Logger for this class
27       */
28      private static final Log LOGGER = LogFactory
29              .getLog(AbstractGhostDomainObject.class);
30  
31      private GhostDomainObjectMapper mapper;
32  
33      /***
34       * Status of the domain object
35       */
36      private LoadStatusEnum status = LoadStatusEnum.GHOST;
37  
38     
39      public final void setMapper(final GhostDomainObjectMapper mapper) {
40          this.mapper = mapper;
41      }
42  
43      /***
44       * mark the object as loading
45       */
46      protected final void markLoading() {
47          status = LoadStatusEnum.LOADING;
48      }
49  
50      /***
51       * mark the object as loaded
52       */
53      protected final void markGhost() {
54          LOGGER.debug("markGhost() - start");
55  
56          status = LoadStatusEnum.GHOST;
57  
58          LOGGER.debug("markGhost() - end");
59      }
60  
61      /***
62       * mark the object as loaded
63       */
64      protected final void markLoaded() {
65          LOGGER.debug("markLoaded() - start");
66  
67          status = LoadStatusEnum.LOADED;
68  
69          LOGGER.debug("markLoaded() - end");
70      }
71  
72      /***
73       * Load the object
74       *
75       * @throws DataSourceException
76       *             DataSourceException
77       */
78      public final void loadForThisObject(final Object object) {
79  
80          LOGGER.debug("loadForThisObject(Object object = " + object
81                  + ") - start");
82  
83          if (isGhost()) {
84              markLoading();
85              mapper.loadForObject(object, this);
86              markLoaded();
87          }
88  
89          LOGGER.debug("loadForThisObject(Object) - end");
90      }
91  
92      /***
93       * Is the object a ghost (ie no data have been loaded )
94       *
95       * @return boolean
96       */
97      protected final boolean isGhost() {
98          LOGGER.debug("isGhost() - start");
99  
100         if (status.equals(LoadStatusEnum.GHOST)) {
101             LOGGER.debug("isGhost() - end - return value = " + true);
102             return true;
103         } else {
104             LOGGER.debug("isGhost() - end - return value = " + false);
105             return false;
106         }
107     }
108 
109     /***
110      * @return loadStatus
111      */
112     protected final LoadStatusEnum getStatus() {
113         return status;
114     }
115 
116     /***
117      * @param enum
118      *            enumeration of status
119      */
120     protected final void setStatus(final LoadStatusEnum enum) {
121         status = enum;
122     }
123 
124 }